<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>分店销售页面</title>
	<link rel="stylesheet" href="../../res/mln/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
    .demoTable{
    	z-index: 10px;
    }
    #addReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #addOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
     #updateReload{
    	position:absolute;
    	top:0%;
    	z-index: 100px;
    	background: rgb(0,0,0,0.9);
    	width:100%;
    	height: 100%;
    	display: none;
    }
    #updateOperation{
    	position: absolute;
    	left: 30%;
    	top: 0%;
    	width: 40%;
    	background: white;
    	
    	
    }
  </style>
</head>
<body>
	<div class="demoTable">
	  搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="date" id="date1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
	  <button class="layui-btn" id="memberAdd" data-type="add">增加</button>
	  <table class="layui-hide" id="fdSell" lay-filter="demo"></table>
	</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit" id="cxxq">查看销售详情</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Invoice">发票</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="InvoiceFd">查看发票</a>
</script>

<script src="../../res/mln/jquery-1.10.2.js"></script>
<script src="../../res/mln/layui-xtree.js"></script>
<script src="../../res/mln/layui.js"></script>
<script src="../../res/js/base.js"></script>
<script src="../../layui/layui.js"></script>
<script>

layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
  
  //日期
  laydate.render({
	    elem: '#date'
  });
  laydate.render({
	    elem: '#date1'
  });

  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#fdSell'
    ,async: false
    ,height: 374
    ,url: path+'fdSell/findAllPage.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'sellId', title: '销售ID', width:120 }
      ,{field: 'sellName', title: '销售人', width:80}
      ,{field: 'sellDates', title: '销售时间', width:180}
      ,{field: 'sellTotalMoney', title: '销售金额', width:120 ,sort: true}
      ,{field: 'sellTotalNumber', title: '销售总数量', width:120,sort: true}
      ,{field: 'serNumber', title: '流水号', width:120}
      ,{field: 'sellMoney', title: '实收款', width:120,sort: true}
      ,{field: 'sellDiscount', title: '折扣', width:120,sort: true}
      ,{field: 'sellChange', title: '找零', width:120,sort: true}
      ,{fixed: 'right',title: '操作', width: 240, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    if(layEvent === 'edit'){
    	var sellId=data.sellId;
    	sessionStorage["sellId"]=sellId;
    	var url="../yuanwei/fdSellList.html?sellId="+sellId;
    	layer.open({
			  type: 2,
			  area : ['75%' , '70%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: [url,'on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			});
    } else if(layEvent === 'salesReturn'){
    	/* var url = path+"salesReturn/findAllFdSellDetail.action";
    	var data={reId:reId};
		$.post(url,data,function(data){
			alert("234");
		}); */
		var sellId = data.sellId;
		//sessionStorage['sellId'] = sellId;
		layer.open({
			title:'分店销售详情'
			,type:2
			,area:['85%','80%']
			//设置滚蛋条 yes为开启  no为关闭
			,content:[path+'pages/mln/fdSellDetail.html?sellId='+sellId,'yes']
		});
 
    }else if(layEvent === 'Invoice'){
    	var invoiceId=data.invoiceId;

    	var goodsTypeName=data.goodsTypeName;
        //使用jquery的ajax方式向后台提交数据
		var url = "../../Invoice/findId";
		var data={invoiceId:invoiceId};
		$.post(url,data,function(data){
			 layer.open({
				  type: 2,
				  area : ['60%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: ['../ykq/Invoice.html','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			 	  success:function(layero,index){
			 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
			 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
			 		  console.log(body.html()) //得到iframe页的body内容
			 		  body.find("#invoiceId").val(data.invoiceId);
			 	  }
				});
		},dataType="JSON");
    }else if(layEvent === 'InvoiceFd'){
    	var invoiceId=data.invoiceId;
    	var goodsTypeName=data.goodsTypeName;
		var url = "../../fdSell/findIdss";
		var data={invoiceId:invoiceId};
		$.post(url,data,function(msg){
			layer.open({
				  type: 2,
				  area : ['60%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  //content: ['../ykq/InvoiceDetail.html?id='+msg[0].sellId,'name='+msg[0].sellName,'on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				  content: ['../ykq/InvoiceDetail.html','on'], 	  
				success:function(layero,index){
			 		 // layer.msg(JSON.stringify(msg.sellId));
			 		 console.log(JSON.stringify(msg));
			 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
			 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
			 		  console.log(body.html()); //得到iframe页的body内容
			 		  body.find("#drugName").val(msg[0].drugName);
			 		 body.find("#sellTotalNumber").val(msg[0].sellTotalNumber);
			 		body.find("#sellDate").val(msg[0].sellDate);
			 		body.find("#drugPrice").val(msg[0].drugPrice);
			 		body.find("#sellTotalMoney").val(msg[0].sellTotalMoney);
			 		body.find("#sellMoney").val(msg[0].sellMoney);
			 		body.find("#sellDiscount").val(msg[0].sellDiscount);
			 		body.find("#sellChange").val(msg[0].sellChange);
			 		body.find("#sellName").val(msg[0].sellName);
			 		 // alert(msg[0].sellId+msg[0].sellName);
			 	  }
				});
		},dataType="JSON");
	 }
    
    });

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					sellName : demoReload.val(),
					dateOne: $("#date").val(),
					dateTwo: $("#date1").val()
				}
				
			});
		});
		$('#closeAdd').on('click', function() {
			$('#addReload').css('display', 'none');
		});
		$('#closeUpdate').on('click', function() {
			
			$('#updateReload').css('display', 'none');
		});
		
		$('#memberAdd').on('click', function() {
			layer.open({
				  type: 2,
				  area : ['85%' , '80%'],//弹出框大小
				  shift:1,//弹出框动画效果
				  content: ['../yuanwei/FdSellDetailadd.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
				});
		});
		
		
		
		
	});
</script>
</body>
</html>